$(document).ready(function(){		
	$("#addUser").val(username);
	
	var src = tl_config.last_url;	
	var i = src.indexOf('?');
	var j =src.indexOf('&');
	if(i!=-1){		
		var id = src.substring(i+4,j);
		var typeName=src.substring(j+10);		
		$("#typeId").val(id);
		$("#typeName").val(typeName);
		$("p#typeNamedesc").text(typeName);
	}	
	
	//表单验证
	var validate = $("#fromDictionary").validate({		   
			rules:{					
				dicName:{
					  required:true,
				      remote: { 
		                   url: server_url+'/rest/dictionary/checkDicName.do?timestamp='+Math.random()+ '&token=' + token,
		                   type: "post",
		                   dataType: "json", 
		                   data: {	
		                	        typeId: function() { return $("#typeId").val();},
		                	        dicName: function() { return $("#dicName").val();}
		                         } 
		               },
		               stringMaxLength:30
				},
				dicValue:{
					  required:true,
				      remote: { 
		                   url: server_url+'/rest/dictionary/checkDicValue.do?timestamp='+Math.random()+ '&token=' + token,
		                   type: "post",
		                   dataType: "json", 
		                   data: {	
		                	       typeId: function() { return $("#typeId").val();},
		                	       dicValue: function() { return $("#dicValue").val();}
		                         } 
		               },
		               stringMaxLength:30
				}
			},
			messages:{				
				     dicName:{
				           required:"该值不能为空！",
	                       remote:"字典名已存在，请重新输入!",
	                       stringMaxLength:"最多能输入30个字符！"
	                   },
	                   dicValue:{
					       required:"该值不能为空！",
		                   remote:"字典值已存在，请重新输入!",
		                   stringMaxLength:"最多能输入30个字符！"
		                 }
			},
			submitHandler:function(){
				sub();
			},
			errorPlacement: function(error, element) {
				if ( element.is(":radio") )
					error.appendTo ( element.parent() );
				else if ( element.is(":checkbox") )
					error.appendTo ( element.parent() );
				else if ( element.is("input[name=captcha]") )
					error.appendTo ( element.parent() );
				else
					error.insertAfter(element);
			},
			validClass : 'rightValidate',
		    success: function(label) {
			   label.html("&nbsp;").text(" ") ;
		    }
	 });	
	
});


//提交
function sub(){	
	if($("#fromDictionary").valid()){
		$.ajax({			
			url:server_url+'rest/dictionary/dictionaryAdd.do?ran='+Math.random()+ '&token=' + token,
			type:'post',
			data:$("#fromDictionary").serialize(),
			success:function(data){
				easyDialog.open({container:{header:'温馨提示',content:data.retMsg},autoClose : 2000});
				back();
			}
		});
	}
}


function back(){
//	$('.g_rightMidden').html("");
//	$(".g_rightMidden").load("dictionaryList.do?ran="+Math.random());
	
	var url="dictionaryList.do?ran="+Math.random();
	tl_config.loadToWorkArea(url);
}
//文本框字数动态显示

function submitCommit(){
	$("#fromDictionary").submit();
}
